from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field


# 基础 Contact Schema
class ContactBase(BaseModel):
    wechat_id: str
    nickname: str
    remark: Optional[str] = None
    relationship_type: Optional[str] = "other"
    description: Optional[str] = None


# 创建联系人的 Schema
class ContactCreate(ContactBase):
    pass


# 更新联系人的 Schema
class ContactUpdate(BaseModel):
    nickname: Optional[str] = None
    remark: Optional[str] = None
    relationship_type: Optional[str] = None
    description: Optional[str] = None


# 数据库返回的 Contact Schema
class ContactInDBBase(ContactBase):
    id: int
    first_interaction: datetime
    last_interaction: datetime

    class Config:
        orm_mode = True


# 返回给API的 Contact Schema
class Contact(ContactInDBBase):
    pass


# 详细联系人信息 Schema，包含更多统计数据
class ContactDetail(Contact):
    message_count: int = 0
    last_message_at: Optional[datetime] = None
    pua_alert_count: int = 0